package com.galudisu.handsonic.modules.system.service.impl;

import com.galudisu.handsonic.modules.system.dao.ResourceDao;
import com.galudisu.handsonic.modules.system.dao.RoleDao;
import com.galudisu.handsonic.modules.system.dao.UserDao;
import com.galudisu.handsonic.modules.system.domain.User;
import com.galudisu.handsonic.modules.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author Barudisshu
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    @Qualifier("userDao")
    private UserDao userDao;

    @Autowired
    @Qualifier("roleDao")
    private RoleDao roleDao;

    @Autowired
    @Qualifier("resourceDao")
    private ResourceDao resourceDao;


    @Override
    public User save(User user) {
        return userDao.save(user);
    }

    @Override
    public User findOne(String userId) {
        return userDao.findOne(userId);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public User findByUsername(String username) {
        return userDao.findByUsername(username);
    }

    @Override
    public Set<String> findRolesByUsername(String username) {
        return roleDao.findIdSetByUsersUsername(username);
    }

    @Override
    public Set<String> findPermissionsByUsername(String username) {
        return resourceDao.findPermissionListByUsersUsername(username);
    }

    @Override
    public void createUser(User user) {
        userDao.save(user);
    }

    @Override
    public void updateUser(User user) {
        userDao.save(user);
    }

    @Override
    public void deleteUser(String id) {
        userDao.delete(id);
    }

    @Override
    public void changePassword(String id, String newPassword) {
        userDao.changePassword(id,newPassword);
    }
}
